package m.server.web.res;

public enum ContentType {
    OTHER("*/*"),
    HTML("text/html"),TEXT("text/plain"),XML("text/xml"),GIF("image/gif"),JPG("image/jpeg"),PNG("image/png"),
    JSON("application/json"),JS("application/javascript"),FILE("application/octet-stream"),PDF("application/pdf"),
    CSS("text/css"),XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),XLS("application/vnd.ms-excel")
    ;
    private final String text;
    ContentType(String t){
        this.text=t;
    }

    /**
     * 后缀名转换类型
     */
    public static ContentType get(String suffix){
        switch (suffix.toUpperCase()) {
            case "TXT": return TEXT;
            case "CSS": return CSS;
            case "XML": return XML;
            case "HTM":
            case "HTML": return HTML;
            case "JS": return JS;
            case "JSON": return JSON;
            case "PNG": return PNG;
            case "JPEG":
            case "JPG": return JPG;
            case "GIF": return GIF;
            case "XLSX": return XLSX;
            case "XLS": return XLS;
            case "PDF": return PDF;
            default: return OTHER;
        }
    }
    @Override
    public String toString() {
        return text;
    }
}
